/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-04-15
 * Time: 23:55
 */
public class Main {
    public static void main(String[] args) {
        MyArray myArray = new MyArray();
        myArray.setVal(0, 10);// 存入Integer
        myArray.setVal(1, "hello");// 存入String

        // 必须强制类型转换，否则编译报错
        String ret = (String) myArray.getPos(1);//getPos方法返回Object类型，但实际存储类型是String所以需要强转
        System.out.println(ret);// 输出：hello
        Integer ret2 = (Integer) myArray.getPos(0);
        System.out.println(ret2);// 输出：10

        // 潜在风险：如果强制转换类型错误，运行时将抛出ClassCastException
        //Integer dangerous = (Integer) myArray.getPos(1); // 运行时错误！
    }
}
